package com.juyu.miliao.scheduler.service;

import com.juyu.miliao.scheduler.dao.redis.GiftWallRedisDao;
import com.juyu.miliao.scheduler.domin.GiftSpend;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 礼物墙
 *
 * @author xuanqicheng
 * @create 2019-18-14:28
 */
@Service
public class GiftWallService {

    @Autowired
    private GiftWallRedisDao giftWallRedisDao;

    /**
     * 设置礼物墙
     *
     * @param giftSpend
     */
    public void setGiftWallInfo(GiftSpend giftSpend) {
        getOldGiftWall(giftSpend);
        getGiftWall(giftSpend);
    }

    /**
     * 新版本礼物墙，版本大于等于1.4.3
     * @param giftSpend
     */
    private void getGiftWall(GiftSpend giftSpend) {
        giftWallRedisDao.setGiftWallListInfo(giftSpend);
    }


    /**
     * 兼容旧版本,版本小于1.4.3
     * @param giftSpend
     */
    private void getOldGiftWall(GiftSpend giftSpend) {
        /**
         * 获取最高礼物价格
         */
        LocalDateTime localDateTime = giftSpend.getCreateTime();

        LocalDate localDate = localDateTime.toLocalDate();

        if (LocalDate.now().equals(localDate)) {
            giftWallRedisDao.setOldGiftWallListInfo(localDate.toString(), giftSpend);
        }
    }

}
